<template>
	<view style="padding: 20px;">
		<button @click="callStorage()">setStorage</button>
		<button @click="callGetStorage()">获取本地缓存</button>
		<button @click="callStorInfo()" type="primary">获取字段列表</button>
		<button @click="callRemove()" type="warn">删除</button>
		<button @click="callClearStorage()" type="warn">删除全部本地缓存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			callStorage() {
				console.log("callStorage");
				uni.setStorage({
					key:"userName",
					data:"testname",
					success() {
						console.log("存储userName成功回调");
					},
					fail() {
						console.error("存储userName失败回调")
					}
				})
			},
			
			callGetStorage() {
				console.log("callGetStorage");
				uni.getStorage({
					key:"userName",
					success:function(result) {
						console.log("获取本地缓存成功："+ result.data);
					},
					fail:function(e) {
						console.error("获取本地缓存失败："+JSON.stringify(e));
						console.error("获取本地缓存失败："+e.errMsg);
					}
				})
			},
			
			callStorInfo() {
				console.log("callStorInfo-->");
				uni.getStorageInfo({
					success:function(result) {
						console.log("callStorInfo-->"+JSON.stringify(result));
						console.log("callStorInfo-->"+result.keys);
					}
				})
			},
			
			callRemove() {
				uni.removeStorage({
					key:"userName",
					success: () => {
						console.log("删除指定key的本地缓存成功");
					},
					fail() {
						console.log("删除失败");
					}
				})
			},
			
			callClearStorage() {
				console.log("callClearStorage-->");
				uni.clearStorage();
			}
			
			
			// onFunCall() {
			// 	name = uni.getStorageSync("userName");//同步接口，立刻执行，阻塞后续代码
			// 	pwd = uni.getStorage("password");//异步接口，异步执行，不阻塞后续代码
			// }
		}
	}
</script>

<style>
button{
	margin: 10px;
}
</style>
